export const ResourceTypeEnums = [
  { value: 1, label: 'PC菜单', color: 'rgba(214, 214, 214)' },
  { value: 2, label: 'APP菜单', color: 'rgba(82,196,26)' },
  { value: 3, label: '页面组件', color: 'rgba(24, 144, 255)' },
  { value: 4, label: '虚拟节点', color: 'rgba(214,214,214)' },
];

export enum ResourceType {
  'PC菜单' = 1,
  'APP菜单',
  '页面组件',
  '虚拟节点',
}

export interface ResTree {
  label: string;
  key: string;
  children: ResTree[];
  [key: string]: any;
}

export function createTree(res: any[]): ResTree[] {
  const _res: ResTree[] = [];
  res.forEach((t) => {
    const item: ResTree = {
      label: t.module,
      key: t.module,
      children: [],
    };

    if (t?.clazzList && t?.clazzList?.length) {
      t.clazzList.forEach((y) => {
        const item1: ResTree = {
          label: y.clazz,
          key: y.clazz,
          children: [],
        };
        if (y?.apiList && y?.apiList?.length) {
          y.apiList.forEach((a) => {
            const item2 = {
              label: `${a.name} (${a.path})`,
              key: a.path,
              path: a.path,
              method: a.method,
              children: [],
            };
            item1.children.push(item2);
          });
        }
        item.children.push(item1);
      });
    }
    _res.push(item);
  });
  return _res;
}
